package com.hxgz.steel.controller.backend;

import com.hxgz.steel.common.Const;
import com.hxgz.steel.common.ResponseCode;
import com.hxgz.steel.common.ServerResponse;
import com.hxgz.steel.domain.Page;
import com.hxgz.steel.domain.User;
import com.hxgz.steel.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "HomeController", description = "后台：首页")
@RestController
@RequestMapping("home")
public class HomeController {

  @Autowired
  HomeService homeService;

  @ApiOperation("首页平台总览数据")
  @RequestMapping(value = "homeTotal.do", method = RequestMethod.POST)
  public ServerResponse homeTotal(HttpServletRequest httpServletRequest) {
    User user = Const.checkBackUserLogin(httpServletRequest);
    if (user == null) {
      return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),
          ResponseCode.NEED_LOGIN.getDesc());
    }
    return homeService.homeTotal();
  }

  @ApiOperation("营收统计")
  @RequestMapping(value = "revenueStatistics.do", method = RequestMethod.POST)
  public ServerResponse revenueStatistics(Page page,
      @ApiParam("时间标签 0本天 1本周 2本月 3本年") @RequestParam(required = false) Integer timeState,
      @ApiParam("开始时间") @RequestParam(required = false) String startTime,
      @ApiParam("结束时间") @RequestParam(required = false) String endTime,
      @ApiParam("订单编号") @RequestParam(required = false) String orderCode,
      @ApiParam("商家名称") @RequestParam(required = false) String merchantName,
      HttpServletRequest httpServletRequest) {
    User user = Const.checkBackUserLogin(httpServletRequest);
    if (user == null) {
      return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),
          ResponseCode.NEED_LOGIN.getDesc());
    }
    return homeService
        .revenueStatistics(page, timeState, startTime, endTime, orderCode, merchantName);
  }


}
